import request from "@/utils/request"

const url = '/uUser'

// 获取验证码
export function getCaptchaAPI(phone) {
    return request({
        url: `${url}/captcha`,
        params: {
            phone
        }
    })
}

// 获取当前用户信息
export function getUserAPI() {
    return request({
        url: `${url}/me`
    })
}

// 验证码登录
export function loginByCaptchaAPI({ phone, code, type=0 }) {
    return request({
        url: `${url}/login`,
        method: 'POST',
        data: {
            type,
            phone,
            code
        }
    })
}

// 密码登录
export function loginByPwdAPI({ phone, password, type=1 }) {
    return request({
        url: `${url}/login`,
        method: 'POST',
        data: {
            type,
            phone,
            password
        }
    })
}

// 修改个人信息
export function updateUserInfoAPI({ address, email, identityNum, realName }) {
    return request({
        url: `${url}/update`,
        method: 'POST',
        data: {
            address,
            email,
            identityNum,
            realName
        }
    })
}

// 退出登录
export function logoutAPI() {
    return request({
        url: `${url}/logout`
    })
}

// 修改密码
export function resetPwdAPI({ password, newPassword, type }) {
    return request({
        url: `${url}/resetPwd`,
        method: 'POST',
        data: {
            password,
            newPassword,
            type
        }
    })
}

// 忘记密码
export function forgetPwdAPI({ code, phone }) {
    return request({
        url: `${url}/forgetPwd`,
        method: 'POST',
        data: {
            code,
            phone
        }
    })
}